package edu.sysu.demo.petstore.dog.key;

import com.google.common.io.BaseEncoding;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;

class PublicKeyConverter extends KeyConverter {

  PublicKeyConverter(BaseEncoding baseEncoding, Provider provider)
      throws NoSuchAlgorithmException {
    super(baseEncoding, provider);
  }

  @Override
  protected PublicKey convert(byte[] bytes, KeyFactory keyFactory)
      throws InvalidKeySpecException {
    return keyFactory.generatePublic(new X509EncodedKeySpec(bytes));
  }
}
